package aufgabe1.teilaufgabe1;

import static org.junit.Assert.*;

import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.List;

import org.junit.Test;

public class TestAlgo {
	
	public static int myRandom(int high) {
		return (int) (Math.random() * high);
	}
	
	@Test
	public void testVarianz() {
		List<Double> list = new ArrayList();
		list.add((double) 20);
		list.add((double) 100);
		list.add((double) 55);
		DecimalFormat f = new DecimalFormat("#0.0000");
		assertEquals(f.format(Algorithm.var(list)),"1072,2222");
		
	}
	
	@Test
	public void testMittelwert() {
		List<Double> list = new ArrayList();
		list.add((double) 20);
		list.add((double) 100);
		list.add((double) 55);
		DecimalFormat f = new DecimalFormat("#0.0000");
		assertEquals(f.format(Algorithm.middle(list)),"58,3333");
		
	}

	@Test
	public void testAlgo100() {
		System.out.println("######################################");
		System.out.println("Test von 100 Zahlen.Wertebereich 0-100");
		System.out.println("######################################");
		List<Double> list = new ArrayList();
		for (int i=0;i < 100;i++){
			list.add((double) myRandom(100));
		}
		long time = 0;
		long timeStartlocal=0;
		long timeEndlocal= 0;
		timeStartlocal = System.nanoTime();
		System.out.println("Varianz: " + Algorithm.var(list));
		timeEndlocal = System.nanoTime();
		time = (timeEndlocal - timeStartlocal);
		System.out.println("Laufszeit: " + time + " Millisek.");
		timeStartlocal = System.nanoTime();
		System.out.println("Varianz: " + Algorithm.middle(list));
	    timeEndlocal = System.nanoTime();
		time = (timeEndlocal - timeStartlocal);
		System.out.println("Laufszeit: " + time + " Millisek.");
		
		
	}
	
	@Test
	public void testAlgo1000() {
		System.out.println("#######################################");
		System.out.println("Test von 1000 Zahlen.Wertebereich 0-100");
		System.out.println("#######################################");
		List<Double> list = new ArrayList();
		for (int i=0;i < 1000;i++){
			list.add((double) myRandom(100));
		}
		long time = 0;
		long timeStartlocal=0;
		long timeEndlocal= 0;
		timeStartlocal = System.nanoTime();
		System.out.println("Varianz: " + Algorithm.var(list));
		timeEndlocal = System.nanoTime();
		time = (timeEndlocal - timeStartlocal);
		System.out.println("Laufszeit: " + time + " Millisek.");
		timeStartlocal = System.nanoTime();
		System.out.println("Varianz: " + Algorithm.middle(list));
	    timeEndlocal = System.nanoTime();
		time = (timeEndlocal - timeStartlocal);
		System.out.println("Laufszeit: " + time + " Millisek.");
		
		
	}
	
	@Test
	public void testAlgo5000() {
		System.out.println("#######################################");
		System.out.println("Test von 5000 Zahlen.Wertebereich 0-100");
		System.out.println("#######################################");
		List<Double> list = new ArrayList();
		for (int i=0;i < 5000;i++){
			list.add((double) myRandom(100));
		}
		long time = 0;
		long timeStartlocal=0;
		long timeEndlocal= 0;
		timeStartlocal = System.nanoTime();
		System.out.println("Varianz: " + Algorithm.var(list));
		timeEndlocal = System.nanoTime();
		time = (timeEndlocal - timeStartlocal);
		System.out.println("Laufszeit: " + time + " Millisek.");
		timeStartlocal = System.nanoTime();
		System.out.println("Varianz: " + Algorithm.middle(list));
	    timeEndlocal = System.nanoTime();
		time = (timeEndlocal - timeStartlocal);
		System.out.println("Laufszeit: " + time + " Millisek.");
		
		
	}
	
	@Test
	public void testAlgo5000Big() {
		System.out.println("###########################################");
		System.out.println("Test von 5000 Zahlen.Wertebereich 0-1000000");
		System.out.println("###########################################");
		List<Double> list = new ArrayList();
		for (int i=0;i < 5000;i++){
			list.add((double) myRandom(1000000));
		}
		long time = 0;
		long timeStartlocal=0;
		long timeEndlocal= 0;
		timeStartlocal = System.nanoTime();
		System.out.println("Varianz: " + Algorithm.var(list));
		timeEndlocal = System.nanoTime();
		time = (timeEndlocal - timeStartlocal);
		System.out.println("Laufszeit: " + time + " Millisek.");
		timeStartlocal = System.nanoTime();
		System.out.println("Varianz: " + Algorithm.middle(list));
	    timeEndlocal = System.nanoTime();
		time = (timeEndlocal - timeStartlocal);
		System.out.println("Laufszeit: " + time + " Millisek.");
		
		
	}
	
	@Test
	public void testAlgoBIG() {
		System.out.println("###########################################");
		System.out.println("Test von 1.000.000 Zahlen.Wertebereich 0-1000000");
		System.out.println("###########################################");
		List<Double> list = new ArrayList();
		for (int i=0;i < 1000000;i++){
			list.add((double) myRandom(1000000));
		}
		long time = 0;
		long timeStartlocal=0;
		long timeEndlocal= 0;
		timeStartlocal = System.nanoTime();
		System.out.println("Varianz: " + Algorithm.var(list));
		timeEndlocal = System.nanoTime();
		time = (timeEndlocal - timeStartlocal);
		System.out.println("Laufszeit: " + time + " Millisek.");
		timeStartlocal = System.nanoTime();
		System.out.println("Varianz: " + Algorithm.middle(list));
	    timeEndlocal = System.nanoTime();
		time = (timeEndlocal - timeStartlocal);
		System.out.println("Laufszeit: " + time + " Millisek.");
		
		
	}

}
